package dao

import (
	"gitee.com/gopher2011/bookman/util"
	"strings"
)

var (
	staticDomain     string
	maxLoginTerminal = 10 //允许最大的登录数（这里暂时写死，后面再设置为可以从数据库中进行配置）
	StoreType        = Cfg.Server.StoreType
)

//存储类型

//更多存储类型有待扩展
const (
	StoreLocal  = "local"
	StoreOss    = "oss"
	VirtualRoot = "virtualroot"
	unknown     = "unknown"
)

func CompleteLink(path string) string {
	if path == "" {
		return ""
	}
	staticDomain = Cfg.Server.StaticDomain
	//存储类型
	if strings.ToLower(StoreType) == StoreOss {
		staticDomain = Cfg.OSS.Domain
	}
	return util.JoinURI(staticDomain, path)
}

//操作图片显示
//如果用的是oss存储，这style是avatar、cover可选项
func ShowImg(img string, style ...string) (url string) {
	if strings.HasPrefix(img, "https://") || strings.HasPrefix(img, "http://") {
		return img
	}
	img = "/" + strings.TrimLeft(img, "./")
	switch StoreType {
	case StoreOss:
		s := ""
		if len(style) > 0 && strings.TrimSpace(style[0]) != "" {
			s = "/" + style[0]
		}
		url = strings.TrimRight(Cfg.OSS.Domain, "/ ") + img + s
	case StoreLocal:
		url = img
	}
	return
}
